package com.golxen.framework.common.server.cross.cmd;


import com.golxen.framework.PBPacket.PBPacket;
import com.golxen.framework.common.server.game.cmd.Command;
import com.golxen.framework.common.server.game.cmd.CommandSet;
import com.googlecode.protobuf.format.JsonFormat;
import com.mysql.cj.util.LogUtils;
import io.netty.channel.ChannelHandlerContext;

public class CrossCommandWrapper implements Runnable {

	private ChannelHandlerContext ctx;

	private PBPacket packet;
	private long receiveTime;

	public CrossCommandWrapper(ChannelHandlerContext ctx, PBPacket packet) {
		this.ctx = ctx;
		this.packet = packet;
		this.receiveTime = System.currentTimeMillis();
	}

	/**
	 * 线程池执行回调，执行线程并推动下一指令的执行
	 */
	@Override
	public final void run() {
		Command cmd;

		try {
			cmd = CommandSet.getCommand(packet.getCode());
			if (cmd == null) {
                throw new RuntimeException(
                        "playerId=" + packet.getPlayerId() + " code=" + packet.getCode() + " is undefined");
            }
			cmd.execute(ctx, packet);
		} catch (Exception e) {
			new Command.Tuple(e, null);
		}



	}
}
